package hbt;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import entities.*;

import java.util.*;

public class RutinaDAO {
	
	private static HibernateDAO hdao;
	
	public RutinaDAO(){
		
	}
	
	public static void persistRutina(Rutina r) {
		System.out.println("Persist rutina");
		System.out.println("ID: "+r.getIdRutina());
		System.out.println("Nombre: "+r.getCliente().getNombre());
		System.out.println("Cantidad items: "+r.getItemsRutina().size());
		
		hdao = HibernateDAO.getInstancia();
		Transaction tran = hdao.getSession().beginTransaction();
		hdao.getSession().persist(r);
		System.out.println("ID despues del persist: "+r.getIdRutina());
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateRutina(Rutina r) {
		System.out.println("Update rutina");
		System.out.println("ID: "+r.getIdRutina());
		System.out.println("Nombre: "+r.getCliente().getNombre());
		System.out.println("Cantidad items: "+r.getItemsRutina().size());
		
		hdao = HibernateDAO.getInstancia();
		Transaction tran = hdao.getSession().beginTransaction();
		hdao.getSession().merge(r);
		tran.commit();
		hdao.closeSession();
	}
	
	public static void SaveOrUpdateRutina(Rutina r) {
		System.out.println("Update rutina");
		System.out.println("ID: "+r.getIdRutina());
		System.out.println("Nombre: "+r.getCliente().getNombre());
		System.out.println("Cantidad items: "+r.getItemsRutina().size());
		
		hdao = HibernateDAO.getInstancia();
		Transaction tran = hdao.getSession().beginTransaction();
		hdao.getSession().saveOrUpdate(r);
		tran.commit();
		hdao.closeSession();
	}
	
	public static int mergeRutina(Rutina r) {
		System.out.println("Update rutina");
		System.out.println("ID: "+r.getIdRutina());
		System.out.println("Nombre: "+r.getCliente().getNombre());
		System.out.println("Cantidad items: "+r.getItemsRutina().size());
		
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Rutina rut = (Rutina) s.merge(r);
		tran.commit();
		int id = rut.getIdRutina();
		s.close();
		hdao.closeSession();
		return id;
	}
	
	public static ItemRutina buscarItemRutinaPorID (int id) {
		hdao = HibernateDAO.getInstancia();
		Transaction tran = hdao.getSession().beginTransaction();
		Query q = hdao.getSession().createQuery("from ItemRutina where idItemRutina = :id ");
		q.setParameter("id", id);
		ItemRutina ir = (ItemRutina) q.uniqueResult();
		tran.commit();
		hdao.closeSession();
		return ir;
	}
	
	public static Rutina buscarRutinaPorID (int id) {
		hdao = HibernateDAO.getInstancia();
		Transaction tran = hdao.getSession().beginTransaction();
		Query q = hdao.getSession().createQuery("from Rutina where idRutina = :id ");
		q.setParameter("id", id);
		Rutina r = (Rutina) q.uniqueResult();
		System.out.println("Cantidad de items: "+r.getItemsRutina().size());
		tran.commit();
		hdao.closeSession();
		return r;
	}
	
	public static void updateRutinaItems1 (String dia) {
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createQuery("from ItemRutina");
		List <ItemRutina> irlist = q.list();
		Iterator i = irlist.iterator();
		while (i.hasNext()){
			ItemRutina ir = new ItemRutina();
			ir.setDia(dia);
			s.persist(ir);
		}
		tran.commit();
		s.close();
		hdao.closeSession();
	}
	
	public static void updateRutinaItem (ItemRutina ir) {
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		s.update(ir);
		tran.commit();
		s.close();
		hdao.closeSession();
	}
	
	//------------------------- MUJER TONIFICAR --------------------------------
	
	public static void updateItemRutinaMT1 () {
		//System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 1 and 15").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMT2 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 1 and 15").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 8){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMT3 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 1 and 15").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 6){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 11){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("viernes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMT4 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 1 and 15").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 5){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 9){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("sabado");
			s.update(ir);
			it.remove();
			cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMT5 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 1 and 15").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 4){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 7){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 10){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("jueves");
			s.update(ir);
			it.remove();
			cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("viernes");
			s.update(ir);
			it.remove();
			cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	//------------------------- MUJER ADELGAZAR --------------------------------
	
	public static void updateItemRutinaMA1 () {
		//System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 16 and 30").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMA2 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 16 and 30").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 8){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMA3 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 16 and 30").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 6){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 11){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("viernes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMA4 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 16 and 30").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 5){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 9){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("sabado");
			s.update(ir);
			it.remove();
			cont++;
	}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaMA5 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 16 and 30").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 4){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 7){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 10){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("jueves");
			s.update(ir);
			it.remove();
			cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("viernes");
			s.update(ir);
			it.remove();
			cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	//------------------------- HOMBRE TONIFICAR --------------------------------
	
	public static void updateItemRutinaHT1 () {
		//System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 31 and 45").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHT2 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 31 and 45").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 8){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHT3 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 31 and 45").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 6){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 11){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("viernes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHT4 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 31 and 45").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 5){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 9){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("sabado");
			s.update(ir);
			it.remove();
			cont++;
	}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHT5 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 31 and 45").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 4){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 7){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 10){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("jueves");
			s.update(ir);
			it.remove();
			cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("viernes");
			s.update(ir);
			it.remove();
			cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
//------------------------- HOMBRE ADELGAZAR --------------------------------
	
	public static void updateItemRutinaHA1 () {
		//System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 46 and 60").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHA2 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 46 and 60").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 8){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHA3 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 46 and 60").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 6){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 11){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("viernes");
				s.update(ir);
				it.remove();
				cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHA4 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 46 and 60").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 5){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 9){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("jueves");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("sabado");
			s.update(ir);
			it.remove();
			cont++;
	}
		tran.commit();
		hdao.closeSession();
	}
	
	public static void updateItemRutinaHA5 () {
		System.out.println("Entro al buscarItemRutinaMT");
		hdao = HibernateDAO.getInstancia();
		Session s = hdao.getSession();
		Transaction tran = s.beginTransaction();
		Query q = s.createSQLQuery("select * from itemsRutina where idItemRutina between 46 and 60").addEntity(ItemRutina.class);
		List <ItemRutina> irlist = q.list();
		Iterator it = irlist.iterator();
		int cont=1;
		while (it.hasNext() && cont < 4){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("lunes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 7){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("martes");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 10){
				ItemRutina ir = new ItemRutina();
				ir = (ItemRutina) it.next();
				ir.setDia("miercoles");
				s.update(ir);
				it.remove();
				cont++;
		}
		while (it.hasNext() && cont < 13){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("jueves");
			s.update(ir);
			it.remove();
			cont++;
		}
		while (it.hasNext() && cont < 16){
			ItemRutina ir = new ItemRutina();
			ir = (ItemRutina) it.next();
			ir.setDia("viernes");
			s.update(ir);
			it.remove();
			cont++;
		}
		tran.commit();
		hdao.closeSession();
	}
}
